// 标签切换
var tabLi = {
	init: function() {
		var baikeTime;
		//新闻
		$("#news_act li").live("mouseover", function () {
			var c = $(this).find('a').attr("class");

			if(c && c.indexOf("on") != -1) return;
			
			tabLi.turnNewsTab(this);
		});
		//游戏介绍
		$("#game_servers_lun li").live("mouseover", function () {
			var c = $(this).find('a').attr("class");
			
			if(c && c.indexOf("on") != -1) return;
			
			tabLi.tunrIntroduction(this);
		});
	},
	
	turnNewsTab: function (me) {
		$("#news_act li a.on").removeClass("on");
		$(me).find('a').addClass("on");
			
		var i = $(me).index();
		
		$(".xinwenhdGroup .xinwenhd_nrs:visible").hide();
		$(".xinwenhdGroup .xinwenhd_nrs").eq(i).show();
	},
	
	tunrIntroduction: function (me) {
		$("#game_servers_lun li a.on").removeClass("on");
		$(me).find('a').addClass("on");
		
		var i = $(me).index();
		
		$(".NewServiceGroup .lun_servers:visible").hide();
		$(".NewServiceGroup .lun_servers").eq(i).show();
	}
}



$(function () {

	tabLi.init();
	
	//热门游戏 显示说明
	$('.HotGame_nrs div').hover(function() {
		$(this).find("div.tanyingBox").css("top", "150px").show().animate({"top": "54px"}, 300);
		
		//hotsGameUrl($(this).index()+1);
	}, function() {
		
		$(this).find("div.tanyingBox").animate({"top": "150px"}, 300, function() {
			$(this).clearQueue();
			$(this).hide();
		});
	});
});


var linkStatus = false;
jQuery(function(){
	var linkBox = jQuery("#friendlinkqu .Friend_nrs");
	jQuery("#friendLinks").click(function(){
		if(linkStatus == true) {
			linkBox.animate({height:'58px'}, 400);
			jQuery(this).attr("class", "icon_link_on");
			linkStatus = false;
		} else {
			
			var h = linkBox.children("a:eq(0)").height() * 4;
			linkBox.animate({"height":h+"px"}, 400);
			jQuery(this).attr("class", "icon_link_off");
			linkStatus = true;
		}
		return false;
	});
});




$(document).ready(function(){	
	autoroll();
	//判断COOKIE
	y3loginusernameindex = getCookie("ZhengDuAccountNameCookie");
 	if(y3loginusernameindex!=""){
		//alert(getCookie("ZhengDuAccountNameCookie"));
		document.getElementById("loginForm").style.display="none";
		document.getElementById("logoutForm").style.display="block";
		
		
		document.getElementById("y3_login_username_index").innerHTML=y3loginusernameindex;
		var y3lastdate = getCookie("ZhengDuloginTimeCookie");
		y3lastdate = y3lastdate.replace("\"","").replace("\"","");
		var y3loginlastip = getCookie("ZhengDuloginIpCookie");
		if(y3loginlastip!=null){
			document.getElementById("y3_login_lastdate").innerHTML=y3lastdate;
		//	document.getElementById("y3_login_lastip").innerHTML=y3loginlastip;
		}
		//document.getElementById("y3_login_ip").innerHTML=getCookie("ZhengDuipCookie");
	}else{
		//document.getElementById("loginForm").style.display="block";
		//document.getElementById("logoutForm").style.display="none";
	}
});
var i=-1;
var offset = 9000;
var timer = null;
	
function autoroll(){
	n = $('.imgc').length-1;
	i++;
	if(i > n){
	i = 0;
	}
	
	slide(i);
   	timer = window.setTimeout(autoroll, offset);
}
function slide(i){	 
	
	//$('.imgc').eq(i).css('display','block').siblings('.imgc').css('display','none');	
	$('.imgc').fadeOut().eq(i).fadeIn().css('display','block').siblings('.imgc').css('display','none');	
}

function lastfn(){

	if (timer) {
		clearTimeout(timer);
		if(i==0)
		i=$('.imgc').length-1;
		else
		i = i-1;
		
		slide(i);
	}
	
	timer = window.setTimeout(autoroll, offset);  
	this.blur();            
	return false;
}
function nextfn(){
	
	if (timer) {
		clearTimeout(timer);
		if(i==($('.imgc').length-1))
		i=0;
		else
		i = i+1;
		
		slide(i);
	}
	
	timer = window.setTimeout(autoroll, offset);  
	this.blur();            
	return false;
   
}
var rightId = 1;
function showBig(flag){
	 
	if(flag!=rightId){
		$('#big'+flag).show();
		$('#small'+flag).hide();
		$('#big'+rightId).hide();
		$('#small'+rightId).show();
		rightId = flag;
	} 
}
function showPic(flag){
	if (timer) {
		clearTimeout(timer);
		 
		i = flag-1;
		
		slide(i);
	}
	
	timer = window.setTimeout(autoroll, offset);  
	this.blur();            
	return false;
}






function keypress(e) 
{ 
var currKey=0,e=e||event; 
if(e.keyCode==13)
{
	if(checkLogoinname()&&checkLogoinpwd())
	document.left_login_form.submit();
	return true; 
}
} 
document.onkeypress=keypress; 

function checkLogoinForm(){
if(checkLogoinname()&&checkLogoinpwd()){
  document.left_login_form.submit();
  return true;
}else{
  return false;
}
}

//用户名非空+长度+合法性验证
function checkLogoinname(){
var name = document.getElementById("username");
if(name.value=="" || name.value=="请输入您的账号"){
  alert("请输入您的账号"); 
  name.focus();
  return false;
}
if(name.value.length<6||name.value.length>16){
  alert("用户名输入的长度6-16个字符");
  name.focus();
  return false;
}
  return true;
}

//密码非空+长度+合法性验证
function checkLogoinpwd(){
var pwd = document.getElementById("password");
if(pwd.value=="" || pwd.value==""  ){
  alert("密码不能为空");  
  pwd.focus();
  return false;
}
if(pwd.value.length<6||pwd.value.length>16){
   alert("密码长度为6-16个字符");
   pwd.focus();
   return false;
}
for(var i=0;i<pwd.value.length;i++)
   {
      var charTest=pwd.value.toLowerCase().charAt(i);
   if( (!(charTest>='0' && charTest<='9')) &&  (!(charTest>='a' && charTest<='z'))  && (charTest!='_') )
   {
      alert("密码包含非法字符，只能包括字母,数字和下划线");
	  pwd.focus();
    return false;
    }
   }
   return true;
}


function getCookie(c_name)
{
if(document.cookie.length>0){
   c_start=document.cookie.indexOf(c_name + "=")
   if(c_start!=-1){ 
     c_start=c_start + c_name.length+1 
     c_end=document.cookie.indexOf(";",c_start)
     if(c_end==-1) c_end=document.cookie.length
     return unescape(document.cookie.substring(c_start,c_end))
   }
}
return ""
}

$(function () {
	$("#r_name").change(function () {
		var r_name = $("#r_name").val();
		if(!/^[\u4E00-\u9FA5]{2,4}$/.test(r_name)){
			$(this).parent().addClass("err");
		}else{
			$(this).parent().removeClass("err");
		}
	});
	$("#r_sfz").change(function () {
		var r_sfz = $("#r_sfz").val();
		if(!/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/.test(r_sfz)){
			$(this).parent().addClass("errs");
		}else{
			$(this).parent().removeClass("errs");
		}
	});
	$("#zc1").click(function () {
		$(".box1").addClass("hide")
		$(".box2").removeClass("hide")
		$("#n1").val("");
		$("#n2").val("");
		$("#r_name").val("");
		$("#r_sfz").val("");
		$("#r_name").parent().removeClass("err");
		$("#r_sfz").parent().removeClass("errs");
	});
	$("#zc2").click(function () {
		$(".box2").addClass("hide")
		$(".box1").removeClass("hide")
		$("#n1").val("");
		$("#n2").val("");
		$("#r_name").val("");
		$("#r_sfz").val("");
		$("#r_name").parent().removeClass("err");
		$("#r_sfz").parent().removeClass("errs");
	});
	$("#dl1").click(function () {
		$(".box2").addClass("hide")
		$(".box1").removeClass("hide")
		$("#n1").val("");
		$("#n2").val("");
		$("#r_name").val("");
		$("#r_sfz").val("");
		$("#r_name").parent().removeClass("err");
		$("#r_sfz").parent().removeClass("errs");
	});
	$("#dl2").click(function () {
		$(".box2").addClass("hide")
		$(".box1").removeClass("hide")
		$("#n1").val("");
		$("#n2").val("");
		$("#r_name").val("");
		$("#r_sfz").val("");
		$("#r_name").parent().removeClass("err");
		$("#r_sfz").parent().removeClass("errs");
	});
})

